#!/bin/bash
# 查看Lambda函数日志

set -e

FUNCTION_NAME="click-event-handler"

echo "📝 Lambda函数日志查看"
echo "================================"

# 获取日志流
echo "最近的日志流："
docker exec browse-etl-localstack awslocal logs describe-log-streams \
  --log-group-name /aws/lambda/$FUNCTION_NAME \
  --order-by LastEventTime \
  --descending \
  --max-items 5 \
  --query 'logStreams[*].[logStreamName, lastEventTime]' \
  --output table

echo ""
echo "选择查看方式："
echo "1) 实时tail (按Ctrl+C停止)"
echo "2) 查看最近100条日志"
read -p "请选择 (1/2): " choice

case $choice in
  1)
    echo "🔄 开始实时监控日志..."
    docker exec -it browse-etl-localstack awslocal logs tail /aws/lambda/$FUNCTION_NAME --follow
    ;;
  2)
    echo "📄 最近100条日志："
    docker exec browse-etl-localstack awslocal logs tail /aws/lambda/$FUNCTION_NAME --n 100
    ;;
  *)
    echo "❌ 无效选择"
    exit 1
    ;;
esac

